﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using System.Globalization;
using System.Collections;
using System.Text.RegularExpressions;
using System.IO;
using System.Data;

public partial class OurLibrary : System.Web.UI.Page
{

    
    /// <summary>
    /// /
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            //GridView1.DataSource = SqlDataSource1;
            //GridView1.DataBind();
        }


    }
    protected override void InitializeCulture()
    {
        if (Session["CurrentCulture"] != null)
        {
            string lang = Session["CurrentCulture"].ToString();
            if (lang != null && lang != "")
            {
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(lang);
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang);
                Thread.CurrentThread.CurrentCulture.DateTimeFormat = new CultureInfo("en-US", false).DateTimeFormat;
                // Thread.CurrentThread.CurrentCulture.Calendar=new  System.Globalization.GregorianCalendar();

            }
        }

    }



    
   

  
   
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        //if (e.Row.RowType == DataControlRowType.DataRow)
        //{
        //    e.Row.Attributes.Add("onmouseover", "this.Mystyle=this.style.backgroundColor;this.style.backgroundColor='#FFFFA8'");

        //    e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=this.Mystyle");
        //}
    }
    protected void Listview1_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        
        if (e.CommandName == "show")
        {

            int ff = int.Parse((e.CommandArgument).ToString());
            //MARCDetails mr = (MARCDetails)((LinkButton)e.CommandSource).NamingContainer.FindControl("MARCDetails1");
            MARCDetails1.setMarc(DB.getMarc(ff));
           ScriptManager.RegisterStartupScript(this.up1, this.GetType(), "hj", "there2();", true);
        }
     

    }

    protected void act_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlDataSource1.SelectCommand = "select p.*,t.product_type from  products p INNER JOIN product_types t ON t.id = p.product_type_id where  p.product_type_id =" + act.SelectedValue;

      
        //GridView1.DataSource = SqlDataSource1;
        ListView1.DataBind();
    }
    protected void allcompanies_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlDataSource1.SelectCommand = "select p.*,t.product_type from  products p INNER JOIN product_types t ON t.id = p.product_type_id where  classification_id =" + allcompanies.SelectedValue;


        //GridView1.DataSource = SqlDataSource1;
        ListView1.DataBind();
    }
    protected void searchfield_TextChanged(object sender, EventArgs e)
    {
        string txt = DB.remove_spaces(searchfield.Text);
        SqlDataSource1.SelectCommand = "select p.*,t.product_type from  products p INNER JOIN product_types t ON t.id = p.product_type_id WHERE product  LIKE '%" + searchfield.Text + "%'  Order BY p.id desc";
        ListView1.DataBind();
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string txt = DB.remove_spaces(searchfield.Text);
        if (DropDownList4.SelectedValue == "0")
        {
            SqlDataSource1.SelectCommand = "select p.*,t.product_type from  products p INNER JOIN product_types t ON t.id = p.product_type_id WHERE product  LIKE '%" + searchfield.Text + "%'  Order BY p.id desc";
        }
        else
        {
            SqlDataSource1.SelectCommand = "select p.*,t.product_type from  products p INNER JOIN product_types t ON t.id = p.product_type_id WHERE " + DropDownList4.SelectedValue + "  LIKE '%" + searchfield.Text + "%'  Order BY p.id desc";
        }

        ListView1.DataBind();
    }
    protected void ImageButton1_Click(object sender, EventArgs e)
    {
        string txt = DB.remove_spaces(searchfield.Text);
        if (DropDownList4.SelectedValue == "0")
        {
            SqlDataSource1.SelectCommand = "select p.*,t.product_type from  products p INNER JOIN product_types t ON t.id = p.product_type_id WHERE product  LIKE '%" + searchfield.Text + "%'  Order BY p.id desc";
        }
        else
        {
            SqlDataSource1.SelectCommand = "select p.*,t.product_type from  products p INNER JOIN product_types t ON t.id = p.product_type_id WHERE " + DropDownList4.SelectedValue + "  LIKE '%" + searchfield.Text + "%'  Order BY p.id desc";
        }

        ListView1.DataBind();
    }
}
